package com.powergisol.gis.model;

import com.vividsolutions.jts.geom.Coordinate;

import java.util.ArrayList;
import java.util.List;

/**
 * 单个岩层面的模型，一般指横向面, 都是跟业务紧密融合的
 */
public class RockPlaneModel extends BaseModel{
    /**
     * 业务属性，属于第几层
     */
    private int level;
    /**
     * 三角网集合
     */
    private List<TriangleMesh> meshs;


    public RockPlaneModel(List<List<Double>> coordinates,List<List<Integer>> conbination,int level){
        this.conbination = conbination;
        this.coordinates = coordinates;
        this.level = level;

        init();
    }

    public int getLevel() {
        return level;
    }


    public List<TriangleMesh> getMeshs() {
        return meshs;
    }

    private void init(){

        if(!this.conbination.isEmpty()){
            throw new RuntimeException("顶点索引不能为空");
        }

        this.conbination.forEach(single ->{

            if(single.size()!=3){
                throw new RuntimeException("三角网顶点必须等于3");
            }

            List<Coordinate> coordinates = new ArrayList<>();

            for (int i = 0; i < single.size(); i++) {

                Integer integer = single.get(i);

                List<Double> doubles = this.coordinates.get(integer);
                double x = doubles.get(0);
                double y = doubles.get(1);
                double z = doubles.get(2);

                if(doubles.size()!=3){
                    throw new RuntimeException("坐标必须由x,y,z 三个数构成");
                }

                Coordinate coordinate = new Coordinate(x,y,z);
                coordinates.add(coordinate);
            }


        });
    }
}
